<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item label="导师编号">
              <a-input v-model="queryParam.dsbh"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="姓名">
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="类型">
              <a-select allowClear v-model="queryParam.shlx">
                <a-select-option :value="1">成功</a-select-option>
                <a-select-option :value="2">失败</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-button type="primary" @click="$refs.table.refresh(true)" style="margin-top:20px">查询</a-button>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        v-if="initDone"
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :data="loadData"
        :alert="{alert: false}"
        :pageSize="parameter.pageSize"
        :pageNum="parameter.pageNum"
        :scroll="{x: 1200}"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter.pageNo - 1) * parameter.pageSize }}
        </span>
        <a slot="dsbh" slot-scope="a, b" @click="direct(b)">{{a}}</a>
      </s-table>
    </a-card>
  </div>
</template>

<script>
import { STable } from '~'

export default {
  data () {
    return {
      queryParam: {},
      columns: [
        {
          title: '序号',
          width: 80,
          scopedSlots: { customRender: 'serial' },
          fixed:'left'
        },
        {
          title: '导师编号',
          dataIndex: 'dsbh',
          width: 120,
          fixed:'left',
          scopedSlots: { customRender: 'dsbh' }
        },
        {
          title: '姓名',
          width: 120,
          dataIndex: 'xm'
        },
        {
          title: '审核前',
          dataIndex: 'shsmq'
        },
        {
          title: '审核后',
          dataIndex: 'shsmh'
        },
        {
          title: '审核人',
          width: 120,
          dataIndex: 'createBy'
        },
        {
          title: '审核日期',
          width: 200,
          dataIndex: 'createDate'
        }
      ],
      parameter: {
        pageNo: 1,
        pageSize: 10
      },
      loadData: parameter => {
        this.parameter = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.teacher.teacherCheckRecordList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {},
      initDone: false
    }
  },
  components: {STable},
  computed: {
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      let pageParams = vm.$store.state.app.pageParams || {}
      if ((from.name === '导师详细信息') && pageParams.path === vm.$route.path) {
        vm.queryParam = pageParams.params
        vm.parameter = pageParams.pagination
      }
      vm.initDone = true
    })
  },
  beforeRouteLeave (to, from, next) {
    if (to.name === '导师详细信息') {
      this.$store.dispatch('app/setPageParams', {
        path: this.$route.path,
        params: this.queryParam,
        pagination: this.parameter
      })
    }
    next()
  },
  created () {

  },
  methods: {
    direct (data) {
      this.$router.push(`/teacher/info/${data.dsbh}`)
    }
  }
}
</script>

<style>

</style>
